<?php
namespace app\index\controller;

use app\data\model\DataUser;
use app\index\model\Users;
use app\mall\model\MallGoodsCate;
use think\admin\Controller;
use think\facade\Db;

class Base extends Controller
{

    protected $uid;
    protected $user_info;

    public function initialize()
    {
      //检测用户登陆状态
      $userID = $this->app->session->get('uid');
      if($userID){
        $userInfo = $this->app->db->name('DataUser')->where('id',$userID)->find();
        $this->assign('userInfo',$userInfo);
        $this->assign('uid',$userID);
      }
      $this->assign('is_login',$this->app->session->get('uid') ? true : false);
      $this->assign('controller', strtolower(request()->controller()));
      $this->assign('action', strtolower(request()->action()));
    }

    /**
     * @name:检查登录
     * @author:Sam
     * @date:2024-09-02
     * @param:[string] param [desc]
    */
    public function  check_login(){
      $userID = $this->app->session->get('uid');
      $this->user_info = $this->app->db->name('DataUser')->where('id',$userID)->find();
      $this->uid = $userID;
      if(empty($userID)){
        return $this->redirect('/login');
      }
    }

        /**
     * 生成订单号
     */
    public static function new_order_sn()
    {
        /* 选择一个随机的方案 */
        mt_srand((double) microtime() * 1000000);
        
        return date('Ymd') . str_pad(mt_rand(1, 999999), 6, '0', STR_PAD_LEFT);
    }


 
}
